package com.ptit.piclient.tools;

import java.util.ArrayList;

import com.ptit.piclient.R;
import com.ptit.piclient.model.Song;

import android.app.Activity;
import android.content.Context;
//import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
//import android.widget.ImageView;
import android.widget.TextView;

public class AllSongAdapter2 extends BaseAdapter {
	private  ArrayList<Song> list;
	private Activity activity;
	public AllSongAdapter2 (Activity a,ArrayList<Song> l){
		//super();
		list = l;
		activity = a;
	}
	public void setList(ArrayList<Song> l){
		list = l;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View vi = convertView;
		LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);        
		if(vi == null){
			vi = inflater.inflate(R.layout.list_row, null);
		}
		//ImageView thumb = (ImageView) vi.findViewById(R.id.thumbnail);
		TextView title = (TextView) vi.findViewById(R.id.title);
		TextView artist = (TextView) vi.findViewById(R.id.artist);
		TextView duration = (TextView) vi.findViewById(R.id.duration);
		Song song = list.get(position);
		if(song == null) {
			//Log.e("nulll", "null song");
			return null;
		}
		title.setText(song.getName());
		artist.setText(song.getFormatedArtist());
		duration.setText(song.getFormatedDuration());
		return vi;
	}

}
